/*
 * @LastEditors: afei
 * @LastEditTime: 2020-12-04 09:39:16
*/
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");

const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
  configureWebpack: config => {
    // config.plugins.push(new HardSourceWebpackPlugin())


    config.plugins.push(new CopyWebpackPlugin({
      patterns:[{
        from: "./static",
        to: 'static'
      }]
    }))
    if (isProduction) {
      config.optimization = {
        splitChunks: {
          chunks: 'all',
          // cacheGroups: {
          //   mockjs: {
          //     name: 'mockjs',
          //     test: /[\\/]node_modules[\\/]mockjs[\\/]/,
          //     priority: -10
          //   },
          //   vendors: {
          //     name: 'vendors',
          //     test: /[\\/]node_modules[\\/]/,
          //     priority: -20
          //   }
          // },
        }
      }

      config.plugins.push(new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: /\.(js|css|svg|woff|ttf|json|html)$/,
        threshold: 10240,
        minRatio: 0.8
      }))
    }
  },

  publicPath: isProduction?'../../':'/',

  devServer: {
      // test
      // proxy: "http://192.168.10.17:8728"
      // dev
      proxy: "http://192.168.104.73:8728"
  },

  // transpileDependencies: [
  //   "three",
  //   'resize-detector'
  // ],

  //module.exports 配置
  productionSourceMap: false,

  chainWebpack: (config) => {
    // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    if (isProduction) {
      config.plugin('compress')
        .use(FileManagerPlugin, [{
          onEnd: {
            delete: [
              './medical/*.zip'
            ],
            archive: [
              {
                source: `./dist`,
                destination: `./medical.zip`
              }
            ]
          }
        }]);
    }
  },

  assetsDir: 'static',
}
